/**
 * 
 */
package com.swim.reservationcoach.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.swim.reservationcoach.entity.ReservationCoach;
import com.swim.common.service.CommonService;
import com.swim.common.utils.SmsUtil;
import com.swim.reservationcoach.dao.ReservationCoachDao;

/**
 * 预约私教Service
 * @author 刘军武
 * @version 2021-05-06
 */
@Service
@Transactional(readOnly=true)
public class ReservationCoachService extends CrudService<ReservationCoachDao, ReservationCoach> {
	
	@Autowired
	private CommonService commonService;
	
	/**
	 * 获取单条数据
	 * @param reservationCoach
	 * @return
	 */
	@Override
	public ReservationCoach get(ReservationCoach reservationCoach) {
		return super.get(reservationCoach);
	}
	
	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param reservationCoach
	 * @return
	 */
	@Override
	public Page<ReservationCoach> findPage(Page<ReservationCoach> page, ReservationCoach reservationCoach) {
		return super.findPage(page, reservationCoach);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param reservationCoach
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(ReservationCoach reservationCoach) {
		super.save(reservationCoach);
		//预约上课信息发送短信给李教练
		String classTimeStr = commonService.getDictDataByDictTypeAndDictValue("class_time", reservationCoach.getClassTime() + "").getDictLabel();
		String reservationCoachMsg = "姓名：" + reservationCoach.getName()
									+"   性别：" + reservationCoach.getSex()
									+"   年龄：" + reservationCoach.getAge()
									+"   区域：" + reservationCoach.getCity() + reservationCoach.getArea()
									+"   手机号码：" + reservationCoach.getMobile()
									+"   上课时间段：" + classTimeStr; 
		try {
//			SmsUtil.sendReservationCoach("15370142983", reservationCoachMsg);
			SmsUtil.sendReservationCoach("13912785198", reservationCoachMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 更新状态
	 * @param reservationCoach
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(ReservationCoach reservationCoach) {
		super.updateStatus(reservationCoach);
	}
	
	/**
	 * 删除数据
	 * @param reservationCoach
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(ReservationCoach reservationCoach) {
		super.delete(reservationCoach);
	}
	
}